﻿using Coolzon.UI.Core.Runtime.Script;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Coolzon.UI.Core.Parts.Widgets
{
    public class Image : Widget
    {
        System.Windows.Controls.Image _image;

        #region XProperties-Fields
        private string _source;
        #endregion

        #region XProperties

        [Category("Appearance")]
        [DisplayName("文字对其模式")]
        [Description("TextAlignment")]
        //[Editor(typeof(XProperty.Editors.XImageSourceFileEditor), typeof(XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Appearance, "Source", "图片地址", false, false)]
        public string Source
        {
            get { return _source; }
            set
            {
                if(string.Equals(_source, value) == false)
                {
                    _source = value;
                    _image.Source = Coolzon.UI.Core.SolutionResouseManager.GetImage(_source);
                }
            }
        }
        
        #endregion

        public Image()
        {
            _image = new System.Windows.Controls.Image();
            this.Content = _image;
        }

        protected override void OnInit(PartContext context)
        {
            base.OnInit(context);
        }

        protected override object OnCreateScriptObject()
        {
            return new ImageScriptObject(this);
        }
    }
}
